#include "cnsComReference.h"
#include <QDebug>
#include "cnsDefaultComFactory.h"

const QString *CnsComReference::getObjFullPath(CnsDefaultComFactory *registry) noexcept
{
    if(_objFullPath)
    {
        return _objFullPath;
    } else{
        _objFullPath = registry->getFullPathFromPathAbbr(*_dirFullPath, _parentFullPath, _objPath);
        return _objFullPath;
    }
}

const QString *CnsComReference::getObjFullPath(CnsDefaultComFactory *registry, const REPLACEPATHLIST &replacePath) noexcept
{
    const QString *objFullPath = getObjFullPath(registry);
    if(replacePath[0].first != replacePath[0].second && objFullPath->contains(replacePath[0].first))
    {
        int size = replacePath[0].first->size();
        if(objFullPath->size() == size || (*objFullPath)[size] == '/')
        {
            QString fullPath = *objFullPath;
            return registry->registerFullPathString(fullPath.replace(*replacePath[0].first, *replacePath[0].second));
        } else{
            return objFullPath;
        }

    } else{
        return objFullPath;
    }
}
